package com.zhangjianling.premp.entity.sys;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * 角色管理
 * @author zhangjl
 *
 */
@Entity
@Table(name="sys_role")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SysRole implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(generator="system-uuid")
	@GenericGenerator(name="system-uuid", strategy="uuid.hex")
	@Column(name="ROLEID", nullable=false)
	private String roleId;

	@Column(name="name")
	private String name;

	@Column(name="remark")
	private String remark;

	@Column(name="createtime",updatable=false)
	private String createTime;

	@Column(name="updatetime")
	private String updateTime;

	@Column(name="createuser",updatable=false)
	private String createUser;

	@Column(name="updateuser")
	private String updateUser;

	@ManyToMany(mappedBy = "roles",cascade={CascadeType.REFRESH},fetch=FetchType.EAGER)
	@JsonIgnore
	private List<SysUser> users = new ArrayList<SysUser>();

	@ManyToMany(cascade = {CascadeType.REFRESH,CascadeType.REMOVE})
	@JoinTable(name = "menu_role",joinColumns = {  @JoinColumn(name = "roleid", referencedColumnName = "roleid") },inverseJoinColumns = {@JoinColumn(name = "menuid", referencedColumnName = "menuid") })
	@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
	@Basic(fetch = FetchType.LAZY)
	@OrderBy("orderRole DESC")
	private List<SysMenu> memus = new ArrayList<SysMenu>();

	
}
